﻿Public Class COMSPHERECLASS
    ''' <summary>
    ''' ID เครื่องคอมพิวเตอร์ (Primary Key)
    ''' </summary>
    ''' <remarks>Primary Key ของ table comsphere</remarks>
    Private COMID As Integer = Nothing
    ''' <summary>
    ''' ID รหัสคลินิกที่คอมพิวเตอร์เครื่องนั้นประจำอยู่
    ''' </summary>
    Private CLINIC As Integer = Nothing
    ''' <summary>
    ''' ชื่อเครื่องคอมพิวเตอร์ (Ex. AOU-IT)
    ''' </summary>
    Private COM_NAME As String = Nothing
    ''' <summary>
    ''' fact แสดงว่าเครื่องนี้ใช้สำหรับทำการเงิน
    ''' </summary>
    Private F_CASHIER = Nothing
    ''' <summary>
    ''' สถานะการเปิดใช้งาน
    ''' </summary>
    Private STATUS = Nothing
    ''' <summary>
    ''' ดึงข้อมูลจาก table comsphere
    ''' </summary>
    Private SelectComsphere = "SELECT `comid` as 'รหัส',masclinic.`clinicname` as 'หน่วยงาน',`com_name` as 'Computer Name',`f_cashier` as 'F_CASHIER',`status` as 'สถานะการเปิดใช้งาน',masclinic.`clinic` FROM comsphere LEFT JOIN (SELECT `clinic`,`clinicname` FROM masclinic WHERE `status` = 1) as masclinic ON comsphere.`clinic` = masclinic.`clinic` "
    ''' <summary>
    ''' connect DB
    ''' </summary>
    Dim connect As CONDB = CONDB.NewConnection
    ''' <summary>
    ''' property COMID
    ''' </summary>
    Property COMID_() As Integer
        Get
            Return COMID
        End Get
        Set(value As Integer)
            COMID = value
        End Set
    End Property
    ''' <summary>
    ''' property CLINIC
    ''' </summary>
    Property CLINIC_() As Integer
        Get
            Return CLINIC
        End Get
        Set(value As Integer)
            CLINIC = value
        End Set
    End Property
    ''' <summary>
    ''' property COM_NAME
    ''' </summary>
    Property COM_NAME_() As String
        Get
            Return COM_NAME
        End Get
        Set(value As String)
            COM_NAME = value
        End Set
    End Property
    ''' <summary>
    ''' property F_CASHIER
    ''' </summary>
    Property F_CASHIER_() As Boolean
        Get
            Return F_CASHIER
        End Get
        Set(value As Boolean)
            If value = True Then
                F_CASHIER = 1
            Else
                F_CASHIER = 0
            End If
        End Set
    End Property
    ''' <summary>
    ''' property STATUS
    ''' </summary>
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    ''' <summary>
    ''' property SelectComsphere
    ''' </summary>
    Property SelectComsphere_() As String
        Get
            Return SelectComsphere
        End Get
        Set(value As String)

        End Set
    End Property
    ''' <summary>
    ''' เพิ่มข้อมูลลง table comsphere
    ''' </summary>
    ''' <remarks>input: property ใน class ได้แก่ CLINIC, COM_NAME, F_CASHIER, STATUS</remarks>
    Public Sub insertcomsphereData()
        'If connect.GetTable("SELECT `TMPID` FROM RGTONBILL WHERE `TMPID` = '" & TMPID & "'").Rows.Count > 0 Then
        '    MsgBox("มีข้อมูลส่วนนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
        'Else
        Try
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            'connectlocal = conlocal.NewConnection()
            Dim Sql As String
            Sql = "INSERT INTO comsphere "
            Sql += "(`clinic`,`com_name`,`f_cashier`,`status`) "
            Sql += " VALUES ("
            If CLINIC = 0 Then
                Sql += "Null"
            Else
                Sql += "'" & CLINIC & "',"
            End If
            Sql += "'" & COM_NAME & "',"
            Sql += "'" & F_CASHIER & "',"
            Sql += "'" & STATUS & "')"
            connect.ExecuteNonQuery(Sql)
            connect.CommitTrans()
            MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
        'End If
    End Sub
    ''' <summary>
    ''' แก้ไขข้อมูลใน table comsphere
    ''' </summary>
    ''' <remarks>input: property ใน class ได้แก่ STATUS, CLINIC, COM_NAME, F_CASHIER, COMID</remarks>
    Public Sub editcomspheredata()
        connect = CONDB.NewConnection()
        connect.BeginTrans()
        Try
            'connectlocal = conlocal.NewConnection()
            Dim sql As String
            sql = "UPDATE comsphere SET`status` = '" & STATUS & "',"
            If CLINIC = 0 Then
                sql += " `clinic` = Null ,"
            Else
                sql += " `clinic` = '" & CLINIC & "',"
            End If
            sql += "`com_name` = '" & COM_NAME & "',"
            sql += "`f_cashier` = '" & F_CASHIER & "' "
            sql += "WHERE `comid` = '" & COMID & "'"
            connect.ExecuteNonQuery(sql)
            connect.CommitTrans()
            MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
    End Sub
End Class
